package com.gl.doc.support;

import java.util.function.BiConsumer;

/**
 * String字符串操作帮助工具类
 */
public class StringSupport {
    /**
     * 获取子字符串在大串中出现的起始下标和结束下标
     *
     * @param subStr   子字符串
     * @param basics   被查找的大串
     * @param consumer 函数式接口（startIndex,endIndex）开始下标和结束下标
     */
    public static void indexOfSupport(String subStr, String basics, BiConsumer<Integer, Integer> consumer) {
        int endIndex = 0;
        do {
            int tempStartIndex = basics.indexOf(subStr);
            if (tempStartIndex == -1) break;
            int tempEndIndex = tempStartIndex + subStr.length();
            basics = basics.substring(tempEndIndex);
            endIndex += tempEndIndex;
            consumer.accept(endIndex - subStr.length(), endIndex - 1);
        } while (true);
    }
}
